const connection = require('../db/mysql')

class UserService {
  //查询单一用户
  async getUserInfoByName (name) {
    let statement = "SELECT * FROM `user` WHERE `name` = ?;";
    const [result] = await connection.execute(statement, [name])
    return result
  }
  //插入注册用户
  async register (name, password) {
    let statement = "INSERT INTO `user` (`name`,`password`) VALUES (?,?)"
    const [result] = await connection.execute(statement, [name, password])
    return result
  }
  //更新用户的充值金额
  async updateAmount (amount, id) {
    let statement = "UPDATE user SET amount = ? WHERE id = ?;";
    const [result] = await connection.execute(statement, [amount, id])
    return result
  }
  // 更新用户头像
  async updateAvatar (avatar, id) {
    console.log(avatar, id)
    let statement = 'UPDATE user SET avatar = ? WHERE id = ?;'
    const [result] = await connection.execute(statement, [avatar, id])
    return result
  }

}

module.exports = new UserService()